package _Cookie;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/setcookie")
public class SetCookieServlet extends HttpServlet{

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	
	
		// 1. 创建Cookie对象
		Cookie c1 = new Cookie("name","zhangsan");
		
		// 2. 设置保存时间（秒)
		c1.setMaxAge(3*60);// 3分钟
//		c1.setMaxAge(10);
		
		// 3. 添加到响应对象中
		resp.addCookie(c1);
		
		
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter pw = resp.getWriter();
		pw.print("设置Cookie");
	
	}
}